/*
 * TltFrame.hpp
 *
 * Copyright 2012 Pieter Agten
 *
 * This file is part of tltgen.
 *
 * tltgen is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * tltgen is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with tltgen.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * @file   TltFrame.hpp
 * @author Pieter Agten (pieter.agten@gmail.com)
 * @date   3 sep 2012
 * @brief  The entry point of the Tltgen GUI.
 */

#ifndef TLTFRAME_HPP
#define TLTFRAME_HPP

#include <wx/wx.h>
#include <wx/notebook.h>
#include <wx/aui/auibook.h>
#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>
#include <vector>

#include "LeastSquaresSolver.hpp"
#include "TablePanel.hpp"

using boost::shared_ptr;
using boost::weak_ptr;

namespace tltgen {

  class TltFrame : public wxFrame {
  public:
    TltFrame(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size);

    enum TemperatureScaleSetting {
      TemperatureScaleCelsius,
      TemperatureScaleFahrenheit,
      TemperatureScaleKelvin,
    };

    void setTemperatureScaleSetting(TemperatureScaleSetting temperatureScaleSetting, bool showMessage = false);
    TemperatureScaleSetting getTemperatureScaleSetting() const;
    shared_ptr<TemperatureScale> getTemperatureScale() const;

    shared_ptr<LeastSquaresSolver> getLeastSquaresSolver() const;

    void addTablePanel(const shared_ptr<ThermistorTable>& thermistorTable);


  protected:
    void createThermistorModels();
    bool hasActiveTablePanel() const;
    TablePanel *GetActiveTablePanel() const;
    void OnNewTable(wxCommandEvent& event);
    void OnOpen(wxCommandEvent& event);
    void OnSaveAs(wxCommandEvent& event);
    void OnImportCsv(wxCommandEvent& event);
    void OnExportRepRap(wxCommandEvent& event);
    void OnExportCsv(wxCommandEvent& event);
    void OnTemperatureScaleCelsius(wxCommandEvent& WXUNUSED(event));
    void OnTemperatureScaleFahrenheit(wxCommandEvent& WXUNUSED(event));
    void OnTemperatureScaleKelvin(wxCommandEvent& WXUNUSED(event));
    void OnAbout(wxCommandEvent& event);
    void OnQuit(wxCommandEvent& event);
    void OnClose(wxCloseEvent& event);

    void OnPageChanged(wxAuiNotebookEvent& event);
    void OnPageClosed(wxAuiNotebookEvent& event);
    void UpdateEnabledMenuOptions();

    void setTemperatureScale(const boost::shared_ptr<TemperatureScale>& temperatureScale);

    DECLARE_EVENT_TABLE();

  private:
    std::locale defaultLocale;

    wxMenu *fileMenu;
    wxMenu *temperatureScaleMenu;
    wxAuiNotebook *notebook;
    shared_ptr<TemperatureScale> temperatureScale;
    shared_ptr<LeastSquaresSolver> solver;

    std::vector<shared_ptr<ThermistorModel> > thermistorModels;
    std::list<weak_ptr<TemperaturePlot> > temperaturePlots;
  };

  enum {
    ID_Quit = 1,
    ID_About,
    ID_NewTable,
    ID_Open,
    ID_ImportCsv,
    ID_ExportRepRap,
    ID_ExportCsv,
    ID_SaveAs,
    ID_Notebook,
    ID_TemperatureScaleCelsius,
    ID_TemperatureScaleFahrenheit,
    ID_TemperatureScaleKelvin,
  };

}

#endif //TLTFRAME_HPP
